# Author    : CoffeeChicken
# Date      : 2020-10-09 16:53
# Function  : 演示 随机生成100张验证码图片

from captcha.image import ImageCaptcha
import string
import random


for _ in range(1000):
    verify_str = ''.join(random.sample(string.ascii_lowercase + string.digits, 4))
    pic_name = verify_str + "_" + ''.join(random.sample(string.ascii_letters + string.digits, 3)) + ".png"
    # 随机生成颜色
    font_rgb = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256))
    background_rgb = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256))
    dot_rgb = (random.randint(0, 256), random.randint(0, 256), random.randint(0, 256))

    # 新建一个ImageCaptcha对象
    img = ImageCaptcha()
    # 生成验证码对象
    image = img.create_captcha_image(verify_str, font_rgb, background_rgb)
    # 生成噪点
    image = img.create_noise_dots(image, dot_rgb, 5, random.randint(20, 40))
    # 保存图片
    image.save("VerificationPics/" + pic_name)
